// package: rewords-server-2024
// filename: queues
// author: diogoxiang@gmail.com
// time: 2024/7/15 下午5:34

package queues

import (
	"context"
	"encoding/json"
	"rewords-server-2024/internal/consts"
	"rewords-server-2024/internal/library/queue"
	"rewords-server-2024/internal/model/entity"
	"rewords-server-2024/internal/service"
)

func init() {
	queue.RegisterConsumer(SysLog)
}

// SysLog 系统日志
var SysLog = &qSysLog{}

type qSysLog struct{}

// GetTopic 主题
func (q *qSysLog) GetTopic() string {
	return consts.QueueLogTopic
}

// Handle 处理消息
func (q *qSysLog) Handle(ctx context.Context, mqMsg queue.MqMsg) (err error) {
	var data entity.SysLog
	if err = json.Unmarshal(mqMsg.Body, &data); err != nil {
		return err
	}
	return service.SysLog().RealWrite(ctx, data)
}
